Skip to content

DOC: Website should copy code only #62108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

DoNguyenHung
Copy link

Changes made:

  • Added sphinx-toggleprompt
  • Removed Python REPL prompts from code after using the copy button in code cells
  • I'm aware that the preferable solution is to sphinx-toggleprompt so users have the choice whether to copy the prompt or not (from add sphinx-copybutton configurations to exclude prompts #59370). However, this toggle is implemented using copybutton, particularly <span class="copybutton" data-hidden="true"> elements (see documentation here). These spans represent the prompt text and are styled with display: none when hidden. However, they share the same copybutton class name as the actual copybutton UI <button class="copybtn">, which introduces ambiguity in the DOM structure. On top of that, when the copy button is clicked, sphinx-copybutton copies the full text content of the target code block. It does not inspect data-hidden="true" or CSS visibility, and it does not differentiate between visible and hidden prompt spans. As a result, REPL prompts are included in the copied output even when they are visually hidden.
  • I tried to override this behavior using custom JavaScript (see my previous commits), but I was unsuccessful because:
    • copybutton and toggleprompt both share the same copybutton class, making it difficult to isolate prompt content from UI elements.
    • The toggle state is not exposed in a way that allows reliable filtering during the copy event.
    • The clipboard API copies raw text content and does not respect DOM visibility or custom attributes like data-hidden (mentioned above).
  • Because of these limitations, I only made changes so that REPL prompts are always stripped from copied output using sphinx-copybutton's built-in prompt removal feature. The toggle remains available for visual clarity, but does not change the copy behavior. If anyone wants to copy the prompt, the best I can recommend is just use toggle and CTRL C + V.

@DoNguyenHung
Copy link
Author

pre-commit.ci autofix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOC: Website should copy code only
1 participant